package com.minggo.charmword.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.minggo.charmword.R;
import com.minggo.charmword.activity.AroundMapActivity;
import com.minggo.charmword.activity.ShakeFindActivity;

/**
 * 整点报时设置页面
 * 
 * @author minggo
 * @time 2014-6-16 S下午9:18:35
 */
public class FragmentFind extends BaseFragment implements OnClickListener {

	private Activity activity;
	private View mainView;
	
	private View rankV;
	private View shockV;
	private View aroundV;
	private View downloadV;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.activity = activity;

	}

	@Override
	public void onDetach() {
		super.onDetach();
		activity = null;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		mainView = inflater.inflate(R.layout.fragment_collection, null);
		initUI();
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		setContentView(mainView);
	}

	
	private void initUI(){
		rankV = mainView.findViewById(R.id.lo_rank);
		shockV = mainView.findViewById(R.id.lo_shock);
		aroundV = mainView.findViewById(R.id.lo_around_people);
		downloadV = mainView.findViewById(R.id.lo_download);
		
		downloadV.setOnClickListener(this);
		aroundV.setOnClickListener(this);
		shockV.setOnClickListener(this);
		rankV.setOnClickListener(this);
	}
	
	/**
	 * 刷新数据
	 */
	public void refreshUI() {
		
	}

	private Handler handler = new Handler(new Callback() {

		@Override
		public boolean handleMessage(Message msg) {
			switch (msg.what) {
			case 1001:
				refreshUI();
				break;

			default:
				break;
			}
			return false;
		}
	});

	@Override
	public void setUserVisibleHint(boolean isVisibleToUser) {
		super.setUserVisibleHint(isVisibleToUser);
	}


	@Override
	protected void showData() {
		setContentShown(false);
		requestData();

	}

	private void requestData() {
		handler.postDelayed(new Runnable() {
			
			@Override
			public void run() {
				setContentShown(true);
			}
		}, 300);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.lo_download:
			
			break;
		case R.id.lo_around_people:
			Intent intent0 = new Intent(activity, AroundMapActivity.class);
			activity.startActivity(intent0);
			break;
		case R.id.lo_shock:
			Intent intent1 = new Intent(activity, ShakeFindActivity.class);
			activity.startActivity(intent1);
			break;
		case R.id.lo_rank:
			
			break;

		default:
			break;
		}
	}

}
